package com.wetalk.stuff;

import com.wetalk.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

public class TriangleShape extends View {

public TriangleShape(Context context, AttributeSet attrs) {
		super(context, attrs);
		TypedArray a = context.obtainStyledAttributes(attrs,
				R.styleable.TriangleShape);
		color = a.getInt(R.styleable.TriangleShape_color,0);
		a.recycle();

	}

	public TriangleShape(Context context) {
		super(context);
	}
	
	

	private int color;
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		// 创建画笔  
        Paint p = new Paint();  
        p.setColor(color);// 设置红色  
        // 绘制这个三角形,你可以绘制任意多边形  
        Path path = new Path();  
        path.moveTo(getLayoutParams().width, 0);// 此点为多边形的起点  
        path.lineTo(0, getLayoutParams().height/2);  
        path.lineTo(getLayoutParams().width, getLayoutParams().height);  
        path.close(); // 使这些点构成封闭的多边形  
        canvas.drawPath(path, p);  
	}
	
	public void setColor(int color) {
		this.color = color;
	}
	

}
